package logic

import (
	"context"
	"hospital/modles"
	"time"

	"hospital/hospital/hospital"
	"hospital/hospital/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGetLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetLogic {
	return &GetLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GetLogic) Get(in *hospital.GetRequest) (*hospital.GetResponse, error) {
	// todo: add your logic here and delete this line
	var Patient []modles.UserDep
	var Data hospital.GetResponse
	modles.DB.Model(&modles.Patient{}).Joins("join deps on patients.dep_id = deps.id").Select("patients.*,deps.dep_name,deps.price").Scan(&Patient)
	for _, dep := range Patient {
		var GetData hospital.GetResponseStruct
		GetData.Name = dep.UserName
		GetData.Image = dep.Image
		GetData.Tel = dep.Tel
		GetData.Price = float32(dep.Price)
		GetData.DepName = dep.DepName
		GetData.CreatedAt = dep.CreatedAt.Format(time.DateTime)
		Data.Users = append(Data.Users, &GetData)
	}
	return &Data, nil
}
